package com.atguigu.gmall.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: lx
 * @Time: 15:40
 * @Description:
 *  Java配置类  配置延迟插件
 */
@Configuration
public class DelayMqConfig {

    public static final String exchange_delay = "exchange.delay";
    public static final String routing_delay = "routing.delay";
    public static final String queue_delay_1 = "queue.delay.1";

    @Bean
    public Queue queueDelay(){
        return QueueBuilder.durable(queue_delay_1).build();
    }
    //延迟插件的交换机配置  类型
    @Bean
    public Exchange exchangeDelay(){
        Map<String, Object> args = new HashMap<String, Object>();
        args.put("x-delayed-type", "direct");//
        return new CustomExchange(exchange_delay, "x-delayed-message",
                true, false, args);
    }
    //
    @Bean
    public Binding bindingDelay(){
        return BindingBuilder.bind(queueDelay()).to(exchangeDelay()).
                with(routing_delay).noargs();
    }


}
